<template>
  <div class="content">
    <BreadNav
      :location="location"
      :routers="routers"
      @getData="getData"
    />
    <main>
      <article>
        <div v-if="!showDetail">
          <keep-alive>
            <Banner
              :imagePlaces="imagePlaces"
              @getData="getData"
            />
          </keep-alive>
          <NewBlog
            :articles="newArticles"
            :isIndex="false"
            @getData="getData"
          />
        </div>
        <ArticleContent v-if="showDetail" />
      </article>
      <aside>
        <AsideTags />
      </aside>
    </main>
    <Footer />
    <Masks
      ref="childRef"
      :bigPicture="bigPicture"
      :isMask="isMask"
      @changeMaskState="changeMaskState"
    />
  </div>
</template>

<script>
import BreadNav from '@/components/BreadNav.vue'
import AsideTags from '@/components/AsideTags.vue'
import Footer from '@/components/Footer.vue'
import NewBlog from '@/components/NewBlog.vue'
import Banner from '@/components/Banner.vue'
import { getArticleList } from '@/api/article'
import Masks from '@/components/Masks.vue'
import ArticleContent from '@/components/ArticleContent.vue'
import bus from '@/main'

export default {
  components: {
    BreadNav,
    Footer,
    AsideTags,
    NewBlog,
    Banner,
    Masks,
    ArticleContent
  },
  data() {
    return {
      location: '博客日记',
      routers: 'bokeriji',
      newArticles: [],
      showDetail: false,
      articleB: {},
      baseURL: this.baseURL,
      imgs: [],
      imagePlaces: [],
      bigPicture: '',
      isMask: false
    }
  },
  computed: {
    images: function () {
      return function (img) {
        return img === '' ? '' : `${this.baseURL}/uploads/${img}`
      }
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    bus.$on('getData', this.getData)
  },
  methods: {
    changeStatus() {
      this.showDetail = true
    },
    async getData() {
      if (this.$route.query.id) {
        this.showDetail = true
      } else {
        this.showDetail = false
        const opt = {
          page: 1,
          per_page: 100,
          channel_id: 1
        }
        const res = await getArticleList(opt)
        this.newArticles = [...res.data.data]
        this.imagePlaces =
          this.newArticles.length >= 4
            ? this.newArticles.splice(0, 4)
            : this.newArticles
        this.newArticles = [...res.data.data]
      }
    },
    large(v) {
      this.bigPicture = v
      this.isMask = true
      this.$refs.childRef.enlarge()
    },
    changeMaskState() {
      this.isMask = false
    },
    previewPicture(e) {
      console.log(e)
      if (e.target.tagName === 'IMG') {
        // this.picturePreview.src = e.target.src;
        // this.picturePreview.visible = true;
        this.bigPicture = e.target.src
        this.isMask = true
        this.$refs.childRef.enlarge()
      }
    }
  }
}
// window.large1 = function (v) {
//   window.mapVue.large1(v);
// };
</script>

<style lang="scss" scoped>
// 宽度大于1201px时
@media screen and (min-width: 1201px) {
  .content {
    width: 1200px;
    margin: 0 auto;
  }
}

// 宽度小于1200px时
@media screen and (max-width: 1200px) {
  .content {
    margin: 0 40px;
  }
  // body .content main article {
  //   width: 80%;
  // }
}

@media only screen and (max-width: 768px) {
  body .content main article {
    width: 100%;
  }
  aside {
    display: none;
  }
}
@media only screen and (max-width: 480px) {
  .content {
    margin: 0 15px;
  }
}

.content {
  main {
    display: flex;
    article {
      width: 860px;
    }
    aside {
      width: 320px;
      margin-left: 20px;
    }
  }
}
</style>
